package k2_oop.p7_javaLang.demo04;

/**
 * 属性 编号，姓名，年龄，工资，身份证号码，员工人数，员工工资总额
 * 构造方法
 *    构造器1：设置编号，年龄，姓名；如果年龄小于18，抛出年龄低异常；如果年龄大于60抛出年龄高异常，如果姓名为null或为空字符串，抛出空异常。
 *    构造器2：设置工资，设置身份证号码；如果工资低于600，抛出工资低异常
 * 普通方法
 *    增加工资 addSalary(double addSalary)，抛出工资高异常，当增加后的工资大于员工工资总额时，抛出此异常。
 *    减少工资 minusSalary(double minusSalary), 抛出工资低异常，当减少后的工资低于政府最低工资时，抛出工资低异常。
 *    显示员工工资总额方法：showTotalSalary(), 抛出空异常，当工资总额为0时，抛出此异常。
 *    显示员工人数：void showTotalEmployee（），抛出空异常。当员工人数为0时，抛出此异常
 */
public class Employee {

    private String empNo;
    private String empName;
    private int age;
    private double salary;
    private String idCard;
    private static int empCount;
    private static double salaryCount;

    public Employee(String empNo, int age, String empName,double salary, String idCard) {

        if(age<18){
            throw new AgeLowException("不能雇佣童工");
        }else if(age>60){
            throw new AgeHighException("太老了");
        }

        if(empName.isEmpty() || empName.isBlank() || empName==null){
            throw new NullException("姓名为空");
        }

        if(salary<600){
            throw new SalaryLowException("吃不起饭了");
        }

        this.empNo = empNo;
        this.age = age;
        this.empName = empName;
        this.salary = salary;
        this.idCard = idCard;
        empCount++;
        salaryCount+=salary;
    }

    public void addSalary(double addSalary){
        double addedSalary = this.salary+addSalary;
        if(addedSalary>salaryCount){
            throw new SalaryHighException("工资太高了");
        }
        this.salary = addedSalary;
        salaryCount+=addSalary;
    }

    public void minusSalary(double minusSalary){
        double minusedSalary = this.salary-minusSalary;
        if(minusedSalary<600){
            throw new SalaryLowException("工资降的太多了");
        }
        this.salary = minusedSalary;
        salaryCount-=minusSalary;
    }

    public static void showTotalSalary(){
        if(salaryCount==0){
            throw new NullException("所有人都没有工资");
        }

        System.out.println("所有员工总工资为："+salaryCount);
    }

    public static void showTotalEmployee(){
        if(empCount==0){
            throw new NullException("没有人干活了");
        }
        System.out.println("现有员工："+empCount);
    }
}
